//
//  HJInformationTabHeader.m
//  KaiChat
//
//  Created by lx on 2024/3/11.
//

#import "HJInformationTabHeader.h"


@interface HJInformationTabHeader()

@property (nonatomic, weak) QMUIButton *rightButton;

@end



@implementation HJInformationTabHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self settingSubView];
    }
    return self;
}

- (void)settingSubView {
    UILabel *titleLabel = [UILabel lableWithSuperView:self font:UIFontMediumMake(16) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(20);
    }];
    _titleLabel = titleLabel;
    
    UIImageView *refreshIconImageView = [UIImageView addToView:self];
    refreshIconImageView.image = [UIImage imageNamed:@"qrCode_refresh"];
    [refreshIconImageView addTapGesturesWithTarget:self action:@selector(tapRightButton)];
    [refreshIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.inset(20);
    }];
    
    QMUIButton *rightButton = [QMUIButton buttonWithSuperView:self font:UIFontMake(12) color:UIColor.tj_333333Color title:nil];
    [rightButton setTitle:@"Change" forState:UIControlStateNormal];
    [rightButton sizeToFit];
    [rightButton addTarget:self action:@selector(tapRightButton) forControlEvents:UIControlEventTouchUpInside];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.equalTo(refreshIconImageView.mas_left).inset(5);
        make.height.offset(20);
        make.width.offset(rightButton.frame.size.width);
    }];
    
    _rightButton = rightButton;
    _refreshIconImageView = refreshIconImageView;
}

- (void)setIsShowRefresh:(BOOL)isShowRefresh {
    _isShowRefresh = isShowRefresh;
    _rightButton.hidden = !isShowRefresh;
    _refreshIconImageView.hidden = !isShowRefresh;
}

- (void)tapRightButton {
    if (self.didClickRightButtonBlock) {
        self.didClickRightButtonBlock(self.refreshIconImageView);
    }
}

@end
